<?php
namespace Wap\Controller;
use Wap\Controller\CommonController;
class TiyanController extends CommonController {

    /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function index() {
  
      $m=M('tiyan');
      $n=M('tylunbo');
      $mendian=$m->select();
      $tylun=$n->order('id desc')->limit(4)->select();
      $count=$m->count();
      $Page=new \Think\Page($count,10);
      $Page -> setConfig('first','首页');
      $Page -> setConfig('last','末页');
      $Page -> setConfig('prev','上一页');
      $Page -> setConfig('next','下一页');

      $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');

      $show = $Page->show();
      $list = $m->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

       
      $this->assign('page',$show);
      $this->assign('tiyan',$list);
       $this->assign('mendian',$mendian);
      $this->assign('tylun',$tylun);



    $this->display(); // 输出模板
    }




    public function yuyue(){
      
      $m=M('yuyue');



      $data['name']=I('post.name');
      $data['address']=I('post.sheng').I('post.shi').I('post.qu');
      $data['tiyan']=I('post.tiyan');
      $data['time']=I('post.time');
      $data['tel']=I('post.tel');
      $data['uid']=$_SESSION['userid'];
       if ($m->add($data)) {
          $this->redirect(U('Tiyan/index'));
       }else{
           $this->error('提交失败',U('Tiyan/index'));

       }


   }
    
 
    public function chengshi(){
      
      $m=M('tiyan');
      $data1=I('post.parm'); 
  
      $data["address"]=array('like','%'.$data1.'%');
      // array('address'=>array("like","%$data%"))
      $result = $m->where($data)->select();
      if($result){
        echo  json_encode($result);
      }else{
        echo 0;
      }


   }



  public function search(){

          $list=M('zlist')->select();
          
          $huxing=M('huxing')->order('id asc')->select();
          
          $fengge = I("get.fengge");
       $huxing1 = I("get.huxing");
       $where = "";

       if(!empty($fengge)){
          $data = M('zlist')->where("id = $fengge")->find();
          if(empty($where)){
            $where .= "a.fengge = '".$data['type_name']."'";
          }else{
            $where .= " and a.fengge = '".$data['type_name']."'";
          }
          
           
       }

       if(!empty($huxing1)){
          $data1 = M('huxing')->where("id=$huxing1")->find();
          if(empty($where)){
            $where .= "a.huxing = '".$data1['huxing']."'";
          }else{
            $where .= " and a.huxing = '".$data1['huxing']."'";
          }
       }
       
       $title=I('post.title');
      $map['a.name'] =array('like',"%$title%");
          $map['a.fengge'] =array('like',"%$title%");
          $map['a.huxing'] =array('like',"%$title%");
          $map['_logic'] = 'or';
    $shangpin=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where($map)->order("a.id desc")->select();
         
            $this->assign("fengge",$fengge);
      $this->assign('list',$list);
      $this->assign('huxing',$huxing);
      $this->assign('huxing1',$huxing1);
            $this->assign('shangpin',$shangpin);
            $this->display();
        
    } 




}
 
?>